const Koa = require('koa')
const router = require('koa-router')()
const { koaBody } = require('koa-body')
const cors = require('koa2-cors')
const koaStatic = require('koa-static')
const path1 = require('path')

const app = new Koa()
const port = 5100

// 跨域
app.use(cors())

// 静态资源访问
app.use(koaStatic(
  path1.join(__dirname, './upload')
))

// 参数解析
app.use(koaBody({
  multipart: true,
  formidable: {
    keepExtensions: true,
    maxFileSize: 3 * 1024 * 1024 * 1024 // 2G
  }
}))

// 路由
app.use(require('./routes/home').routes())
app.use(require('./routes/user').routes())
app.use(require('./routes/third-party').routes())
app.use(require('./routes/file').routes())
app.use(require('./routes/test').routes())
app.use(router.allowedMethods())

app.listen(port)

console.log('starting at on http://localhost:%d', port)
